#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>

#define LEN 1023

int hosts_setup()
{
  FILE *fcp1, *fcp2;
  char len[LEN+1];
  FILE *gipv61;

  fcp1 = fopen( "/etc/hosts.miredo", "r");
  if(fcp1 == (FILE *)NULL)
  {
      fprintf( stderr, "文件读取失败\n");
      return(-1);
  }

  fcp2 = fopen( "/etc/hosts", "w");
  if(fcp2 == (FILE *)NULL)
  {
      fprintf( stderr, "文件以写入方式打开失败\n");
      return(-1);
  }

  while((fgets( len, LEN, fcp1)) != NULL)
  {
      fputs( len, fcp2 );
  }

  fclose(fcp2);
  fclose(fcp1);

  gipv61 = fopen( "/tmp/gipv6", "w");
  if( gipv61 == (FILE *)NULL )
  {
      fprintf( stderr, "标记文件创建失败\n");
  }
  else
  {
    fprintf( gipv61, "%d", getpid());
  }

  fclose(gipv61);
  return(0);
}
